package com.qi.pojo.vo;

import com.qi.common.Status;
import com.qi.exception.ServerException;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class AjaxResult {
    private int code;
    private String msg;
    private Object data;

    private AjaxResult(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static AjaxResult success() {
        return new AjaxResult(Status.SUCCESS.getCode(), Status.SUCCESS.getMsg(), null);
    }

    public static AjaxResult ok(String msg) {
        return new AjaxResult(Status.SUCCESS.getCode(), msg, null);
    }

    public static AjaxResult success(Object data) {
        return new AjaxResult(Status.SUCCESS.getCode(), Status.SUCCESS.getMsg(), data);
    }

    public static AjaxResult success(String msg, Object data) {
        return new AjaxResult(Status.SUCCESS.getCode(), msg, data);
    }

    public static AjaxResult error(Status status) {
        return new AjaxResult(status.getCode(), status.getMsg(), null);
    }

    public static AjaxResult error(ServerException e) {
        return new AjaxResult(e.getCode(), e.getMsg(), null);
    }

    public static AjaxResult error(String msg) {
        return new AjaxResult(-1, msg, null);
    }
}
